﻿using System.Collections.Generic;
using facebook.Schema;
using System;

namespace facebook
{
	/// <summary>
	/// Facebook application api methods.
	/// </summary>
	public class links
	{
		private readonly API _api;
		/// <summary>
		/// Public constructor for facebook.links
		/// </summary>
		/// <param name="parent">Needs a connected API object for making requests</param>
		public links(API parent)
		{
			_api = parent;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
        public IList<link> get()
        {
            return get(0);
        }
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
        public IList<link> get(long uid)
		{
			var parameterList = new Dictionary<string, string> { { "method", "facebook.links.get" } };
            _api.AddOptionalParameter(parameterList, "uid", uid);

			var response = _api.SendRequest(parameterList);
			return !string.IsNullOrEmpty(response) ? links_get_response.Parse(response).link : null;
		}
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public long post(long uid, Uri url, string comment)
        {
            var parameterList = new Dictionary<string, string> { { "method", "facebook.links.post" } };
            _api.AddRequiredParameter(parameterList, "uid", uid);
            _api.AddRequiredParameter(parameterList, "url", url.ToString());
            _api.AddRequiredParameter(parameterList, "comment", comment);

            var response = _api.SendRequest(parameterList, !string.IsNullOrEmpty(_api.SessionKey));
            return !string.IsNullOrEmpty(response) ? links_post_response.Parse(response).TypedValue : -1;
        }
    }
}
